#region

using System;
using System.Collections.Generic;
using CommandLineMapper.Interfaces;

#endregion

namespace CommandLineMapper {
    public class ObjectMappingResult : IObjectMappingResult {
        private readonly IList<string> _allKeys;
        private readonly int _allKeysCount;

        private readonly IDictionary<string, string> _keysMapped
            = new Dictionary<string, string>();

        private readonly IList<string> _keysUnmapped;

        public ObjectMappingResult(IEnumerable<string> keys) {
            if (keys == null) {
                throw new ArgumentNullException("keys");
            }
            _allKeys = new List<string>(keys);
            _allKeysCount = _allKeys.Count;
            _keysUnmapped = new List<string>(keys);
        }

        #region Implementation of IObjectMappingResult

        public IList<string> AllKeys {
            get { return _allKeys; }
        }

        public IDictionary<string, string> KeysMapped {
            get { return _keysMapped; }
        }

        public IList<string> KeysUnmapped {
            get { return _keysUnmapped; }
        }

        public int AllKeysCount {
            get { return _allKeysCount; }
        }

        public void AddMap(string key, string propertyName) {
            if (String.IsNullOrEmpty(key)) {
                throw new ArgumentNullException("key");
            }
            if (String.IsNullOrEmpty(propertyName)) {
                throw new ArgumentNullException("propertyName");
            }
            if (!AllKeys.Contains(key) || KeysMapped.ContainsKey(key)) {
                return;
            }

            KeysMapped.Add(key, propertyName);
            KeysUnmapped.Remove(key);
        }

        #endregion
    }
}